<?php 
class CartWS_Model_SalesOrderHdrProperty extends CartWS_Model_FormulaEngine_Table
{
	protected $_name = 'sc_sales_order_hdr_property';
	protected $_sequence = 'sc_sales_order_property_seq';
        protected $_referenceMap = array(
        'CartWS_Model_SalesOrderHdr' => array(
            'columns'           => 'sales_order_id',
            'refTableClass'     => 'CartWS_Model_SalesOrderHdr',
            'refColumns'        => 'sales_order_id'
        ));

	public function getAll ( $orderId ) 
	{
		$rowset = $this->fetchAll(
			$this->select()->where('sales_order_id=?', $orderId)
		);
		if(count($rowset)) {
			return $rowset;
		}
		return array();
	}
	
	public function getProperty( $orderId, $property )
	{
		$row = $this->fetchRow(
			$this->select()
			->where('sales_order_id=?', $orderId)
			->where('property=?',$property)
		);
		if( isset($row)){
			return $row->value;
		}
		return false;
	}
	
	public function addProperty($orderId, $property, $value)
	{
		$row = $this->fetchRow(
			$this->select()
			->where('sales_order_id=?', $orderId)
			->where('property=?',$property)
		);
		if( !count($row)){
			$row = $this->createRow();
			$row->sales_order_id = $orderId;
			$row->property = $property;
		}
		$row->value = $value;
		return $row->save();
	}
}